package com.cps116.friendstracker;


import com.easy.facebook.android.facebook.FBLoginManager;
import com.easy.facebook.android.facebook.Facebook;
import com.easy.facebook.android.facebook.LoginListener;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;


public class FacebookConnect extends Activity implements LoginListener {

	private FBLoginManager fbManager;
	private Intent profileIntent;


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		profileIntent= new Intent(getApplicationContext(),ProfileActivity.class);

		shareFacebook();
	}

	public void shareFacebook() {
		String permissions[] = {
				getString(R.string.facebook_auth_perm_offline_access),
				getString(R.string.facebook_auth_perm_publish_checkins),
				getString(R.string.facebook_auth_perm_read_friendlists),
				getString(R.string.facebook_auth_perm_user_checkin),
				getString(R.string.facebook_auth_perm_user_friends_checkins),
				getString(R.string.facebook_auth_perm_user_friends_locations),
				getString(R.string.facebook_auth_perm_user_location) 
				};

		fbManager = new FBLoginManager(this,R.layout.black,"271255199579605",permissions);

		if (fbManager.existsSavedFacebook()) {
			fbManager.loadFacebook();
		} else {

			fbManager.login();
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		fbManager.loginSuccess(data);
	}

	public void loginFail() {
		fbManager.displayToast("Login failed!");

	}

	public void logoutSuccess() {
		fbManager.displayToast("Logout success!");
	}

	public void loginSuccess(Facebook facebook) {
		
		//set facebook only once...
		((FriendsTrackerApplication) getApplication()).setFacebook(facebook);
		startActivity(profileIntent);
				
	}	
	




}